package com.cftpay.payexperience.usage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cftpay.payexperience.R;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import sdk.pay.model.PayTypeModel;


/**
 * Created by Joe_PC on 2016/2/16,
 * For MyApplication.
 */
public class PayTypeAdapter extends BaseAdapter {
    private List<PayTypeModel> mArrayList;
    private LayoutInflater mInflater;
    ViewHolder holder;

    public PayTypeAdapter(Context context, List<PayTypeModel> arrayList) {
        mArrayList = arrayList;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mArrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return mArrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_listviewlayout, parent, false);
            holder = new ViewHolder();
            holder.mImageType = (ImageView) convertView.findViewById(R.id.image_type);
            holder.mName = (TextView) convertView.findViewById(R.id.text_name);
            holder.mImageChecked = (ImageView) convertView.findViewById(R.id.image_checked);
            convertView.setTag(holder);
            AutoUtils.auto(convertView);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String s = mArrayList.get(position).getTypeid().substring(0, 2);
        if (s.equals("WX")) {
            holder.mImageType.setImageResource(R.drawable.icon_wechat);
            holder.mName.setText(parent.getResources().getString(R.string.wechat));

        } else if (s.equals("ZF")) {
            holder.mImageType.setImageResource(R.drawable.icon_alipay);
            holder.mName.setText(parent.getResources().getString(R.string.alipay));

        } else if (s.equals("QQ")) {
            holder.mImageType.setImageResource(R.drawable.icon_qqpay);
            holder.mName.setText(parent.getResources().getString(R.string.qqpay));

        } else if (s.equals("JD")) {
            holder.mImageType.setImageResource(R.drawable.icon_jdpay);
            holder.mName.setText(parent.getResources().getString(R.string.jdpay));

        } else {
            holder.mImageType.setImageURI(null);

        }
        return convertView;
    }

    private static final class ViewHolder {
        ImageView mImageType;
        TextView mName;
        ImageView mImageChecked;
    }
}
